<?php
    header("Content-type:text/html;charset=utf-8");

    //接受前端的数据
    
    // 建立链接
    $con=mysql_connect("localhost","root","123456");
   
    //选择数据库
    mysql_select_db("xiaozi");
    mysql_query("set character set 'utf8'");//读库
    mysql_query("set names 'utf8'");//写库
    //查询商品信息表
    $result=mysql_query("SELECT *  FROM goodsinfo",$con);

    if(!$result){
        die("获取数据失败".mysql_error());
        
    }

    $response = "[";
		while($row = mysql_fetch_array($result)){
			$response = $response.'{'.'"goodsId":"'.$row["goodsId"].'"'.','.'"goodsName":"'.$row["goodsName"].'"'.','.'"goodsPrice":"'.$row["goodsPrice"].'"'.','.'"goodsCount":"'.$row["goodsCount"].'"'.','.'"goodsImg":"'.$row["goodsImg"].'"'.'},';
		}
		$response = substr($response,0,strlen($response)-1)."]";
    //向前端返回数据
    echo $response;
    //关闭连接
    mysql_close($con);
   
?>